using net_work.Config;
using net_work.Data.DTO.Hmw;
using net_work.Data.Entity.Hmw;
using net_work.IRepository.Hmw;

namespace net_work.Repository.Hmw;

public class BankAnswerRepository(ApplicationDbContext dbContext)
    : Repository<BankAnswer>(dbContext), IBankAnswerRepository
{
    public async Task<long> InsertAsync(BankAnswerAddRequest bankAnswerAddRequest)
    {
        var newBankAnswer = new BankAnswer
        {
            Remark = bankAnswerAddRequest.Remark,
            Content = bankAnswerAddRequest.Content,
            QuestionId = bankAnswerAddRequest.QuestionId
        };
        await dbContext.BankAnswers.AddAsync(newBankAnswer);
        await dbContext.SaveChangesAsync();
        return newBankAnswer.Id;
    }

    public async Task<bool> UpdateAsync(BankAnswerUpdateRequest bankAnswerUpdateRequest)
    {
        var bankAnswer = await dbContext.BankAnswers.FindAsync(bankAnswerUpdateRequest.Id);
        if (bankAnswer == null)
        {
            return false;
        }

        bankAnswer.Remark = bankAnswerUpdateRequest.Remark;
        bankAnswer.Content = bankAnswerUpdateRequest.Content;
        bankAnswer.QuestionId = bankAnswerUpdateRequest.QuestionId;

        await dbContext.SaveChangesAsync();
        return true;
    }
}